﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Drawing;
using System.Drawing.Design ;
 

 
 
using DotSpatial.Data;

using DotSpatial.Symbology;

using DotSpatial.Topology;
using DotSpatial.Serialization;


using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.Windows.Forms ;
using System.Windows.Forms.Design ;


namespace HaGisPack
{



    [Serializable ]
    public class FELineLayer : FShapeLayer
    {

        public FELineLayer(string id):base(id)
        {
            this.m_Type = FeatureType.Line;

            //this.DataSet = new Shapefile (this.m_Type);

            this.Configure();
            
        }    

        protected override void BuildLayer()
        {
            base.BuildLayer();
            //this._LineSymbol = (this.ILayer as IFeatureLayer).Symbolizer;        
            (this.ILayer as IFeatureLayer).Symbolizer = this._LineSymbol as LineSymbolizer;
        }


        #region "属性封装"
        [NonSerialized]
        private object _LineSymbol = new LineSymbolizer(Color.Black, 1);

        [Editor(typeof(LineSymbolEditor), typeof(UITypeEditor))]
        [Category("基本信息"),DisplayName ("线基本信息设置")]
        public object LineSymbol
        {
            get 
            { 
                return _LineSymbol; 
            }
            set
            {
                this._LineSymbol = value;
                this.OnSetSymbol();
            }
        }

        protected void OnSetSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).Symbolizer = (LineSymbolizer)this._LineSymbol;
        }

        //-------------------------------------------------------

        [NonSerialized ]
        private object _SelectSymbol = new LineSymbolizer();

        [Editor(typeof(LineSymbolEditor), typeof(UITypeEditor))]
        [Category("基本信息"), DisplayName("所选图形信息设置")]
        public virtual object SelectionSymbol
        {
            get { return _SelectSymbol; }
            set
            {
                this._SelectSymbol = value;
                this.OnSetSelectSymbol();
            }
        }

        protected void OnSetSelectSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).SelectionSymbolizer = (LineSymbolizer)this._SelectSymbol;
        }





        #endregion



        # region  protected methods


        public override void SaveEntity()
        {
            base.SaveEntity();


            XmlSerializer xs = new XmlSerializer();
            //string xmlLayer = xs.Serialize(this.ILayer);
            //File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Layer.xml", xmlLayer);

            string xmlSymbol = xs.Serialize(this._LineSymbol);
            File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Symbol.xml", xmlSymbol);

            string xmlSelectSymbol = xs.Serialize(this._SelectSymbol);
            File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "SelectSymbol.xml", xmlSelectSymbol);

            //string xmlLabel = xs.Serialize(this._LabelLayer);
            //File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Label.xml", xmlLabel);

        }


        public override void LoadEntity()
        {
            base.LoadEntity();

            XmlDeserializer xd = new XmlDeserializer();

            //string xmlLayer = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Layer.xml");                            
            //xd.Deserialize(this.ILayer, xmlLayer);
            //this.ILayer = xd.Deserialize<DotSpatial.Controls.IMapLayer>(xmlLayer);

            string xmlSymbol = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Symbol.xml");
            this._LineSymbol = xd.Deserialize<LineSymbolizer>(xmlSymbol);

            string xmlSelectSymbol = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "SelectSymbol.xml");
            this._SelectSymbol = xd.Deserialize<LineSymbolizer>(xmlSelectSymbol);

            //string xmlLabel = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Label.xml");
            //xd.Deserialize(this._LabelLayer, xmlSymbol);

        }

        # endregion



    }
}
